﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ProjectBase.Core;
using ProjectBase.Data.NH;
using ProjectBase.Mvc;

using $prjsn$.Entity.Services;
using $prjsn$.Common;
using $prjsn$.Common.Data.Services;
using $prjsn$.Common.Business.Services;
using $prjsn$.Data;
using $prjsn$.Business;

namespace $safeprojectname$.Services
{
    /// <summary>
    /// This TEST class is derived from base EntityTestBase with template 'T'.
    /// and is directly equipped with two properties:
    /// 'Facade' of type IUserProfileFacade - already lazily created and supplied with
    /// 'Messages' of type IList of ApplicationMessage; - for information exchange.
    /// Next steps should be:
    ///
    /// 1) implement the 'MakeItValid' method, use it for testing of 'working' entities
    /// 2) adjust Create, Update and Delete tests
    /// 3) append your new specific ones
    /// </summary>
    [TestClass]
    public class UserProfileTest : EntityTestBase<IUserProfileFacade>
    {
        #region MakeItValid
        /// <summary>
        /// RE-use. Let's this method converts any entity into valid one (once)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        protected virtual UserProfile MakeItValid(UserProfile entity)
        {
            Messages.Clear();
            entity = entity ?? Facade.CreateNew(); // FACTORY METHOD design pattern

            // TODO - fill needed properties to meet the Business rules
            //entity.Code = "Test1" + Guid.NewGuid();
            //entity.Name = entity.Code;
            //entity.IsVisible = true;

            return entity;
        }
        #endregion MakeItValid

        #region Get
        /// <summary>
        /// Try to test your filtering criteria as much as possible.
        /// Check correctnes of the UserProfileFilter and UserProfileDao objects
        /// </summary>
        [TestMethod]
        public void Find()
        {
            var current = Facade
                .Find(new UserProfileFilter { TakeRows = 1 })
                .FirstOrDefault();
            if (current.IsNull())
            {
                Assert.Inconclusive("Missing any persistent entity: '{0}', cannot run Find test".FormatWith("UserProfile"));
            }

            var filter = new UserProfileFilter
            {
                IdExact = current.ID,
                // TODO  add more
                TakeRows = 1,
            };

            filter.ProjectionList[Str.Common.ID] = null;

            var result = Facade.Find(filter);
            Assert.IsTrue(result.Count() > 0, " there must be UserProfile entity which meets provided filtering criteria ");
        }
        #endregion Get

        #region InUse - Delete

        /// <summary>
        /// Essential TEST !!!!!
        /// !!!!!!!!!!!!!!!!!!!!
        ///
        /// Assure there, that UserProfile entity cannot be delted, when is used by another entity!
        /// It will help you! soon, you'll see...
        /// </summary>
        [TestMethod]
        public void IsUserProfileInUse()
        {
            Messages.Clear();

            // Test the business rules, that the UserProfile entity cannot be deleted while used (referenced)

        }
        #endregion InUse - Delete

        #region Additional test attributes
        // constructor
        public UserProfileTest() { }

        [ClassInitialize]
        public static void MyClassInitialize(TestContext testContext) { }

        [ClassCleanup]
        public static void MyClassCleanup() { }

        [TestInitialize]
        public override void MyTestInitialize() { base.MyTestInitialize(); }

        [TestCleanup]
        public override void MyTestCleanup() { base.MyTestCleanup(); }
        #endregion Additional test attributes
    }
}
